package com.woniu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.entity.dto.FundFlowDTO;
import com.woniu.entity.vo.FundFlowVO;
import com.woniu.entity.vo.UserOrderNoPayDetailsVO;
import com.woniu.entity.vo.UserOrderPayDetailsVO;
import com.woniu.entity.vo.UserOrderVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.entity.dto.QueryOrderDTO;
import com.woniu.entity.vo.DetailOrderVO;
import com.woniu.entity.vo.ListOrderVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.entity.dto.QueryOrderDTO;
import com.woniu.entity.vo.DetailOrderVO;
import com.woniu.entity.vo.ListOrderVO;
import com.woniu.pojo.Order;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import org.apache.ibatis.annotations.Select;

import java.util.List;

import java.util.List;

/**
* @author Ma.Lei
* @description 针对表【t_order】的数据库操作Mapper
* @createDate 2022-12-16 23:28:04
* @Entity generator.domain.Order
*/
public interface OrderMapper extends BaseMapper<Order> {

     IPage<FundFlowVO> queryFundFlow(IPage<FundFlowVO> page, FundFlowDTO fundFlowDTO);
    @Select("SELECT  \n" +
            "a.order_code,a.order_status,b.car_number,c.berth_code,d.road_name,a.create_time,\n" +
            "a.parking_time\n" +
            "FROM t_order a,\n" +
            "(SELECT id,car_number from t_car WHERE is_deleted = 0) b,\n" +
            "(SELECT id,berth_code FROM t_berth WHERE is_deleted = 0) c,\n" +
            "(SELECT id,road_name FROM t_road WHERE is_deleted = 0) d\n" +
            "WHERE a.car_id = b.id and a.berth_id = c.id and a.road_id = d.id\n" +
            "and a.user_id=#{id} and a.order_status=#{status} and a.is_deleted = 0;")
    @ResultType(UserOrderVO.class)
    List<UserOrderVO> listOrder(String id, String status);

    @Select("SELECT leave_time,parking_time FROM t_order WHERE order_code = #{orderCode} and is_deleted = 0;")
    Order getByCode(String orderCode);

    @Update("update t_order set parking_time = #{timeDiff} where order_code = #{orderCode}")
    void setOrderParkTime(String orderCode, String timeDiff);

    @Select("SELECT  \n" +
            "a.order_code,a.order_status,b.car_number,c.berth_code,d.road_name,a.create_time,\n" +
            "a.parking_time\n" +
            "FROM t_order a,\n" +
            "(SELECT id,car_number from t_car WHERE is_deleted = 0) b,\n" +
            "(SELECT id,berth_code FROM t_berth WHERE is_deleted = 0) c,\n" +
            "(SELECT id,road_name FROM t_road WHERE is_deleted = 0) d\n" +
            "WHERE a.car_id = b.id and a.berth_id = c.id and a.road_id = d.id\n" +
            "and a.order_code= #{orderCode} and a.is_deleted = 0;")
    @ResultType(UserOrderVO.class)
    UserOrderVO orderOngoingDetails(String orderCode);

    @Select("SELECT  \n" +
            "a.order_code,b.car_number,c.berth_code,d.road_name,a.create_time,\n" +
            "a.parking_time,a.order_status,a.leave_time,a.price\n" +
            "FROM t_order a,\n" +
            "(SELECT id,car_number from t_car WHERE is_deleted = 0) b,\n" +
            "(SELECT id,berth_code FROM t_berth WHERE is_deleted = 0) c,\n" +
            "(SELECT id,road_name FROM t_road WHERE is_deleted = 0) d\n" +
            "WHERE a.car_id = b.id and a.berth_id = c.id and a.road_id = d.id\n" +
            "and a.order_code=#{orderCode} and a.is_deleted = 0;")
    @ResultType(UserOrderNoPayDetailsVO.class)
    UserOrderNoPayDetailsVO orderNoPayOrFinishDetails(String orderCode);

    @Select("SELECT  \n" +
            "a.order_code,b.car_number,c.berth_code,d.road_name,a.create_time,\n" +
            "a.parking_time,a.order_status,a.leave_time,a.price,a.pay_time\n" +
            "FROM t_order a,\n" +
            "(SELECT id,car_number from t_car WHERE is_deleted = 0) b,\n" +
            "(SELECT id,berth_code FROM t_berth WHERE is_deleted = 0) c,\n" +
            "(SELECT id,road_name FROM t_road WHERE is_deleted = 0) d\n" +
            "WHERE a.car_id = b.id and a.berth_id = c.id and a.road_id = d.id\n" +
            "and a.order_code=#{orderCode} and a.is_deleted = 0;")
    @ResultType(UserOrderPayDetailsVO.class)
    UserOrderPayDetailsVO orderPayDetails(String orderCode);

    @Select("SELECT * from t_order WHERE order_code = #{orderCode}")
    @ResultType(Order.class)
    Order selectByOrderCode(String orderCode);

    @Select("SELECT  \n" +
            "a.order_code,b.car_number,c.berth_code,d.road_name,a.create_time,\n" +
            "a.parking_time,a.order_status\n" +
            "FROM t_order a,\n" +
            "(SELECT id,car_number from t_car WHERE is_deleted = 0) b,\n" +
            "(SELECT id,berth_code FROM t_berth WHERE is_deleted = 0) c,\n" +
            "(SELECT id,road_name FROM t_road WHERE is_deleted = 0) d\n" +
            "WHERE a.car_id = b.id and a.berth_id = c.id and a.road_id = d.id\n" +
            "and a.user_id = #{id} and b.car_number = #{carNum} and a.order_status=2 and a.is_deleted = 0;\n")
    List<UserOrderVO> listOrderByCarNum(String id,String carNum);

    @Select("SELECT a.* from t_order a,t_car b \n" +
            "WHERE a.car_id = b.id and b.car_number=#{carNum} \n" +
            "and a.order_status in('1','2');")
    @ResultType(Order.class)
    List<Order>  checkCarNum(String carNum);
    @Select("select * from t_order where order_code = #{out_trade_no}")
    Order getByOrderCode(String out_trade_no);

    Boolean createOrder(Order order);

    IPage<ListOrderVO> listSearch(IPage<ListOrderVO> page, QueryOrderDTO queryOrderDTO);

    List<ListOrderVO> exportByDTO(QueryOrderDTO queryOrderDTO);

    DetailOrderVO getDetailById(String id);

}




